<?php
/**
 *                    _ooOoo_
 *                   o8888888o
 *                   88" . "88
 *                   (| -_- |)
 *                    O\ = /O
 *                ____/`---'\____
 *              .   ' \\| |// `.
 *               / \\||| : |||// \
 *             / _||||| -:- |||||- \
 *               | | \\\ - /// | |
 *             | \_| ''\---/'' | |
 *              \ .-\__ `-` ___/-. /
 *           ___`. .' /--.--\ `. . __
 *        ."" '< `.___\_<|>_/___.' >'"".
 *       | | : `- \`.;`\ _ /`;.`/ - ` : | |
 *         \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 *                    `=---='
 *
 * .............................................
 *          佛祖保佑             永无BUG
 */

namespace App\Admin\Export;


use App\OrderPay;
use Encore\Admin\Grid\Exporters\AbstractExporter;
use Maatwebsite\Excel\Facades\Excel;

class OrderHanleExport extends AbstractExporter
{
    public function export()
    {
//dd($this->getData());
        Excel::create('Order List', function($excel) {

            $excel->sheet('Order List', function($sheet) {
                $rows1=collect([['流水号','付款金额','订单金额','支付方式','收货人','手机号','物流','退款状态','支付时间','下单时间']]);
                // 这段逻辑是从表格数据中取出需要导出的字段
                $rows = collect($this->getData())->map(function ($item) {
                    return [
                        $item['pay_sn'],
                        $item['pay_price'],
                        $item['total_money'],
                        OrderPay::$payTypeMap[$item['pay_type']] ?? '未知',
                        $item['consignee'],
                        $item['mobile'],
                        OrderPay::$shipStatusMap[$item['ship_status']],
                        OrderPay::$refundStatusMap[$item['refund_status'] ?? 'pending'],
                        $item['paid_at'],
                        $item['create_time']

                        ];
                });
                $sheet->rows($rows1);
                $sheet->rows($rows);

            });

        })->export('xls');

    }
}